const hd = function () {
    // <!--推广位置统计-->
    (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?9cf3075d2f6b03afedf5cf5de9e612bd";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
    if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
        //手机端统计
        (function () {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?a34193dc92085b7d3e1e746627ce435b";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();

    } else {
        (function () {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?5a64c36e04cedc2deb51ec4451adc81b";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    }

    function getCookie(name, key) {
        var reg = new RegExp("(^| )" + name + "=([^;]*)(;|)");
        var arr = document.cookie.match(reg);
        if (arr != null) return unescape(arr[2]).substring(key);
        else return "";
    }

    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.trim().substr(1).match(reg); //匹配目标参数
        if (r != null) return unescape(r[2]);
        else return ""; //返回参数值
    }
    var uidParam = getCookie('uidCookie') != "" ? getCookie('uidCookie', 4) : getUrlParam('uid'); //"uid=" 长度为"4"
    var cpParam = getCookie('cpCookie') != "" ? getCookie('cpCookie', 4) : getUrlParam('coupon'); //"cid=" 长度为"4"
    var wxParam = getCookie('wxCookie') != "" ? getCookie('wxCookie', 4) : getUrlParam('wxnumber'); //"wid=" 长度为"4"
    //var addUid = uidParam!=""?"uid=" + uidParam:"";
    var addUid = "uid=" + uidParam;
    var addCid = "coupon=" + cpParam;
    var addWid = "wxnumber=" + wxParam;
    document.querySelectorAll('a').forEach(function (n) {
        if (n.href.indexOf("uid=") >= 0)
            return;
        var haveParam = n.href.indexOf("?") >= 0 ? "1" : "0"; //判断是否已经有参数
        if (haveParam == "1") {
            if (uidParam != "" && cpParam != "" && wxParam != "") {
                n.href = n.href + "&" + addUid + "&" + addCid + "&" + addWid;
            }
            if (uidParam != "" && cpParam != "" && wxParam == "") {
                n.href = n.href + "&" + addUid + "&" + addCid;
            }
            if (uidParam != "" && cpParam == "" && wxParam != "") {
                n.href = n.href + "&" + addUid + "&" + addWid;
            }
            if (uidParam != "" && cpParam == "" && wxParam == "") {
                n.href = n.href + "&" + addUid;
            }
            if (uidParam == "" && cpParam != "" && wxParam != "") {
                n.href = n.href + "&" + addCid + "&" + addWid;
            }
            if (uidParam == "" && cpParam != "" && wxParam == "") {
                n.href = n.href + "&" + addCid;
            }
            if (uidParam == "" && cpParam == "" && wxParam != "") {
                n.href = n.href + "&" + addWid;
            }
            if (uidParam == "" && cpParam == "" && wxParam == "") {
                return
            }
        }
        if (haveParam == "0") {
            if (uidParam != "" && cpParam != "" && wxParam != "") {
                n.href = n.href + "?" + addUid + "&" + addCid + "&" + addWid;
            }
            if (uidParam != "" && cpParam != "" && wxParam == "") {
                n.href = n.href + "?" + addUid + "&" + addCid;
            }
            if (uidParam != "" && cpParam == "" && wxParam != "") {
                n.href = n.href + "?" + addUid + "&" + addWid;
            }
            if (uidParam != "" && cpParam == "" && wxParam == "") {
                n.href = n.href + "?" + addUid;
            }
            if (uidParam == "" && cpParam != "" && wxParam != "") {
                n.href = n.href + "?" + addCid + "&" + addWid;
            }
            if (uidParam == "" && cpParam != "" && wxParam == "") {
                n.href = n.href + "?" + addCid;
            }
            if (uidParam == "" && cpParam == "" && wxParam != "") {
                n.href = n.href + "?" + addWid;
            }
            if (uidParam == "" && cpParam == "" && wxParam == "") {
                return
            }
        }
    });
}
export default hd;